package com.example.icongyou;


import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;


import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.android.material.bottomnavigation.BottomNavigationView;

public class BottomMenuActivity extends AppCompatActivity {

    private BottomNavigationView bottomNavigationView;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bottom_menu);

        bottomNavigationView = findViewById(R.id.bottom_navigation);

        // 设置默认 Fragment (例如：主页)
        loadFragment(new TeacherMainFragment());

        // 设置导航项选择监听器
        bottomNavigationView.setOnItemSelectedListener(new BottomNavigationView.OnItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                Fragment selectedFragment = null;

                // 根据 ID 判断点击了哪个菜单项
                int itemId = item.getItemId();
                if (itemId == R.id.homeFragment) {
                    selectedFragment = new TeacherMainFragment();
                } else if (itemId == R.id.planSquareFragment) {
                    showToast("跳转到方案广场");
                } else if (itemId == R.id.newCourseFragment) {
                    selectedFragment = new CreateCourseFragment();
                } else if (itemId == R.id.courseFragment) {
                    selectedFragment = new CourseCenterFragment();
                } else if (itemId == R.id.myFragment) {
                    selectedFragment = new ProfileSettingsFragment();
                }

                // 加载选中的 Fragment
                if (selectedFragment != null) {
                    loadFragment(selectedFragment);
                    return true;
                }
                return false;
            }
        });
    }

    /**
     * 加载 Fragment 到容器中
     * @param fragment 要显示的 Fragment 实例
     */
    private void loadFragment(Fragment fragment) {
        // 获取 Fragment 事务
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        // 替换容器中的内容
        transaction.replace(R.id.fragment_container, fragment);
        // 提交事务
        transaction.commit();
    }
    private void showToast(String message) {
        // 在 Activity 中，直接使用 this 作为 Context
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }


}